package thread;

import java.util.*;

public class SynAoiDemo {

            public static void main(String[] args) throws InterruptedException {
            List<Integer> c = Collections.synchronizedList(new ArrayList<>());
                //Set<Integer> c = new HashSet<>();

                Thread t1 = new Thread(){
                    public void run(){
                        for (int i = 0; i < 1000; i++) {
                            c.add(i);
                        }
                    }
                };
                Thread t2 = new Thread(){
                    public void run(){
                        for (int i = 1000; i < 2000; i++) {
                            c.add(i);
                        }
                    }
                };

                t1.start();
                t2.start();

                Thread.sleep(50);

                System.out.println(c.size());

            }
        }

